# 连接数据库
from pymysql import *

conn = connect(host='localhost', user='root', password='123456', database='dbm', port=3306)
cursor = conn.cursor()

def querys(sql, params, type='no_select'):
    # 把参数转换为元组（所传参数为dict字典）
    params = tuple(params)
    # 执行sql语句
    cursor.execute(sql, params)
    # 如果是查询语句则进入该条件语句
    if type != 'no_select':
        data_list = cursor.fetchall()
        conn.commit()
        # 把查询的表结果存入 data_list 并返回
        return data_list
    else:
        conn.commit()
        return "数据库语句执行成功"

